
<template>
  <el-dialog :close-on-click-modal="false"
             title="查看采购合同"
             v-el-drag-dialog
             :visible.sync="formVisible">
    <el-form ref="dataForm" v-if="JSON.stringify(form) != '{}'" :model="form"
             label-position="left" size="small"
             label-width="100px" style="width: 400px; margin-left:50px;">
      <el-form-item label="主键">
        <span class="form-item-show">
          {{ form.id }}
        </span>
      </el-form-item>
      <el-form-item label="执行部门">
        <span class="form-item-show">
          <span>{{ form.dept | findEnumLabel(dictionaryEntry['执行部门']) }}</span>
        </span>
      </el-form-item>
      <el-form-item label="名称">
        <span class="form-item-show">
          {{ form.name }}
        </span>
      </el-form-item>
      <el-form-item label="编码">
        <span class="form-item-show">
          {{ form.code }}
        </span>
      </el-form-item>
      <el-form-item label="签订日期">
        <span class="form-item-show">
          <span>{{ form.signDate | utoDateToBeijing }}</span>
        </span>
      </el-form-item>
      <el-form-item label="采购金额（元）">
        <span class="form-item-show">
          {{ form.money }}
        </span>
      </el-form-item>
      <el-form-item label="采购内容">
        <span class="form-item-show">
          {{ form.content }}
        </span>
      </el-form-item>
      <el-form-item label="合同文件">
        <span class="form-item-show">
          <span> <a target="_blank" v-for="item in getFileAndImg(form.filePath)" :href="fileDomain + '/' + item.path" download>{{item.name}}</a></span>
        </span>
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="formVisible = false">
        取消
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import purchaseContractApi from '@/api/platformAnweiguo/purchaseContract'
import fileDomainApi from '@/api/develop/fileDomain'
import { mapGetters } from 'vuex'
import elDragDialog from '@/directive/el-drag-dialog'

export default {
  name: 'PurchaseContractShow',
  directives: { elDragDialog },
  data() {
    return {
      fileDomain: '',
      dictionaryEntry: {},
      options: {},
      form: {
       // id: null,
       
       // dept: null,
       
       // name: null,
       
       // code: null,
       
       // principalPartId: null,
       
       // signDate: null,
       
       // money: null,
       
       // content: null,
       
       // filePath: null
       
      },
      formVisible: false
    }
  },
  computed: {
    ...mapGetters([
      'dictList'
    ])
  },
  created() {
    this.getDictionaryEntry()
    this.getFileDomain()
  },
  methods: {
    getFileDomain () {
      fileDomainApi.fileDomain().then(res => {
        this.fileDomain = res.data
      })
    },
    getFileAndImg (value) {
      if (!value) {
        return []
      }
      let valueArray = value.split(";");
      let list = [];
      for (let i = 0; i < valueArray.length; i++) {
        list.push(JSON.parse(valueArray))
      }
      return list;
    },
    getDictionaryEntry () {
      //获取字典项
      const dictionaryEntry = JSON.parse(sessionStorage.getItem('constCode'))
      dictionaryEntry.forEach(item => {
        if (!(item.constName in this.dictionaryEntry)) {
          this.dictionaryEntry[item.constName] = []
        }
        this.dictionaryEntry[item.constName].push({
          label: item.name,
          value: item.value
        })
      })
    },
    /**
     * 点击选项卡
     */
    handleClick(){
      //切换选项卡，清空选择数组状态
      this.selectItems = []
    },
    /**
     * 打开查看表单
     */
    handleShow(row) {
      this.form = Object.assign({}, row)
      this.formVisible = true
    },
    /**
     * 展示文件详情
     * @param row
     */
    handleFilePathFileShow(file){
     // TODO...
    },
   
  }
}
</script>
